﻿
//选择组类型
function SelGroupType()
{
    if($("GroupType_1")!=null && $("GroupType_1").checked)
    {
        $("gtExchange").style.display="none";
        $("gtOther").style.display="none";
        $("gtStudy").style.display="";
        $("gtStudy2").style.display="";
        $("selLang1").style.display="";
        $("selLang2").style.display="";        
    }
    else if($("GroupType_2")!=null && $("GroupType_2").checked)
    {
        $("gtExchange").style.display="";
        $("gtOther").style.display="none";
        $("gtStudy").style.display="none";
        $("gtStudy2").style.display="none";
        $("selLang1").style.display="";
        $("selLang2").style.display="";        
    }
    else if($("GroupType_3")!=null && $("GroupType_3").checked)
    {
        $("gtExchange").style.display="none";
        $("gtOther").style.display="";
        $("gtStudy").style.display="none";
        $("gtStudy2").style.display="none";
        $("selLang1").style.display="none";
        $("selLang2").style.display="";       
    }
}

//提交group
function SaveGroup()
{
    if(__P_M==""){$Login$();return;}
    var valTitle = $("txtTitle").value;
    //内容
    var valDesc = "";
    try{valDesc=FCKeditorAPI.GetInstance('txtDesc1').GetXHTML(true); }catch(e){}    
    if(valTitle.length<3 || valTitle.length>110)
    {
        $scroller$("TitleID",100);
        $("txtTitle").focus();       
        $("ErrorTitle").style.display = "";
        return;
    }
    $("ErrorTitle").style.display = "none"; 
    //语言   
    if(($("GroupType_1").checked || $("GroupType_2").checked)&&$("selLang1").value=="")
    {
        $scroller$("selLang1",100);
        $("Errorlearn").style.display = "";
        return;
    }
    $("Errorlearn").style.display = "none";
    if($("selLang2").value=="")
    {
        $scroller$("selLang2",100);
        $("ErrorBase").style.display = "";
        return;
    }
    $("ErrorBase").style.display = "none";
    if(valDesc.length<3 || valDesc.length>10000)
    {
        FCKeditorAPI.GetInstance('txtDesc').Focus();
        $("ErrorDesc").style.display = "";
        return;
    }
    $("ErrorDesc").style.display = "none";  
    var valTags = "";
    var elments = $("tbTag").getElementsByTagName("input");
    for (var i = 0; i < elments.length; i++)
    {
        if(elments[i].type=="checkbox" && elments[i].checked)
        {
            valTags += elments[i].value+" ";
        }
    }
    //tag验证 
    var tags = $("TagsText").value;
    var tagArr = tags.split(" ");    
    if(tags.indexOf("-")!=-1||tags.indexOf("/")!=-1)
    {
        $("ErrorTags").style.display = "";
        return;        
    }
    for(var i = tagArr.length-1; i >=0; i--)
    {
        if(tagArr[i].length>50)
        {
            $("ErrorTags").style.display = "";
            return;     
        }
    }    
    valTags += tags;
    if(valTags.split(" ").length>25)
    {
        $("ErrorTags").style.display = "";
        return;
    }
    $("ErrorTags").style.display = "none"; 
    //图片格式
    var valImage = $("fileDocs").value;
    if(valImage!="")
    {
        valImage = valImage.substr(valImage.lastIndexOf('.') + 1).toLowerCase();
        if(valImage!="jpg"&&valImage!="png"&&valImage!="gif"&&valImage!="jpeg")
        {
            $("ErrorImage").style.display = "";
            return;
        }
    }
    $("ErrorImage").style.display = "none";
    $get("btnSave").disabled = true;
    showProgressBar(false,true);    
    var obj = $get("Form1");
    obj.action = "/groups/SaveGroup.aspx?gid="+gid+"&groupID="+groupID;
    if(obj!=null)obj.submit();
}